package com.wqtz.chechai.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.wqtz.chechai.R;
import com.wqtz.chechai.base.rebaseadapter.MyHolder;
import com.wqtz.chechai.base.rebaseadapter.RecyclerAdapter;
import com.wqtz.chechai.bean.CarInfo;

import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2016/12/22 14:42
 */

public class CarInfoAdapter extends RecyclerView.Adapter<CarInfoAdapter.ViewHolder> {
	List<CarInfo> data ;
	CallBack callBack ;

	public CarInfoAdapter(List<CarInfo> data, CallBack callBack) {
		this.data = data;
		this.callBack = callBack;
		Logger.e(data.size()+" ");
	}

	@Override
	public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_car_info, null);
		return new ViewHolder(view);

	}

	@Override
	public void onBindViewHolder(CarInfoAdapter.ViewHolder holder, final int position) {
		holder.mTextView.setText(" "+data.get(position).getResult().getBody().getCARINFO());
		Logger.e(data.get(position).getResult().getBody().getCARINFO());
		holder.mTextView.setOnClickListener(new View.OnClickListener() {
			@Override public void onClick(View v) {
				callBack.OnitemOnclick(position);
			}
		});

	}

	@Override
	public int getItemCount() {
		return data==null?0:data.size();
	}

   class ViewHolder extends RecyclerView.ViewHolder {
	   private TextView mTextView;

	   public ViewHolder(View itemView) {
			super(itemView);
			mTextView = (TextView) itemView.findViewById(R.id.tv_car_info);
		}
	}

	public interface CallBack{
		void OnitemOnclick(int position);
	}
}
